<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="file" name="file" id="fileInput" accept="image/png, image/jpeg">
    <img src="" alt="图片" id="img">
</body>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
    // 获取input标签元素
    document.getElementById('fileInput').addEventListener("change",(e)=>{
        // console.log(e.target.files);
        // 将伪数组转为数组
        Array.from(e.target.files).map((f,i)=>{
            // 构造form表单数据
            let formData = new FormData();
            formData.append("file",f);
            // 使用axios发送数据
            axios.post("http://localhost:3000/uploadImg",formData).then(res=>{
                let url = "https://10.36.140.22:6001/uploads/"+res.data.url;
                document.getElementById('img').setAttribute('src',url);
            }).catch(err=>console.log(err));
        });
    });
</script>
</html>